#===- ./Makefile -------------------------------------------*- Makefile -*--===#

LEVEL := ../..

main_target=exportbc.so $(BINDIR)/rbcc

include $(LEVEL)/Makefile.rules

R ?= R
COMPILER ?= bc.R

$(BINDIR)/rbcc: Makefile compile.R.in
	$(Echo) Generating $@
	$(Verb) mkdir -p $(BINDIR) && cat compile.R.in | sed "s:RCMD:$R:" | sed "s:PATH:$$PWD:" > $@
	$(Verb)	chmod a+x $@

exportbc.so: exportbc.c $(LEVEL)/lib/bc.c
	$(Echo) Generating $@
	$(Verb) $R CMD SHLIB exportbc.c $(LEVEL)/lib/bc.c $(LDFLAGS)
	$(Verb) \rm $(LEVEL)/lib/bc.o

image: exportbc.so $(COMPILER) compile.R
	$R --slave -f  compile.R --args $(COMPILER) -lR

clean:
	$(Echo) Local cleaning
	$(Verb) rm -Rf exportbc.so exportbc.o bc.Rc $(LEVEL)/lib/bc.o $(BINDIR)/rbcc
